//
//  HZZFAppDelegate.m
//  HZZFAdSDK
//
//  Copyright (c) 2025 早范. All rights reserved.
//

#import "HZZFAppDelegate.h"
#import <HZZFAdSDK/HZZFAdSDK.h>
#import <HZZFAdSDK/HZZFAdSDKSplashAd.h>
#import "HZZFViewController.h"
@interface HZZFAppDelegate ()<HZZFAdSDKSplashAdDelegate>

@property(nonatomic, strong) HZZFAdSDKSplashAd *splashAd;

@end

@implementation HZZFAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[HZZFViewController new]];
    [self.window makeKeyAndVisible];
    

    [HZZFAdSDK initWithAppId:@"444444" completionBlock:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"====sdk初始化失败，err:%@", error.localizedDescription);
        } else {
            NSLog(@"====sdk初始化成功");
        }
    }];
    // Override point for customization after application launch.
    
    [self loadSplash];
    return YES;
}


- (void)loadSplash{
    self.splashAd = [[HZZFAdSDKSplashAd alloc] init];
    self.splashAd.showTime = 5;
    self.splashAd.delegate = self;
    self.splashAd.controller = self.window.rootViewController;
    self.splashAd.setSkipButtonToRightTop = YES;
    self.splashAd.posId = @"59052052";

    /// 加载开屏广告
    [self.splashAd loadSplashAd];
}

#pragma mark - HZZFAdSDKSplashAdDelegate

/**
 开屏广告加载成功
 
 @param splashAd 开屏对象
 */
- (void)HZZF_splashAdDidLoad:(HZZFAdSDKSplashAd *)splashAd {
    NSLog(@"%s,===%@", __func__, [splashAd getRequestId]);
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [splashAd showSplashAdInWindow:window];
}

/**
 开屏广告点击回调, 可能会打开 AppStore, WebView, ThirdApp etc.

 @param splashAd 开屏广告
 @param loadingPageURL 广告落地页地址，当渠道为bwt，并且customLoadingPage为YES时有值
 */
- (void)HZZF_splashAdDidClick:(HZZFAdSDKSplashAd *)splashAd loadingPageURL:(NSString *)loadingPageURL {
    NSLog(@"%s,===%@", __func__, [splashAd getRequestId]);
 
}

/**
 开屏广告关闭回调, 触发条件: 点击广告, 点击跳过, 超时关闭

 @param splashAd 开屏对象
 */
- (void)HZZF_splashAdDidClose:(HZZFAdSDKSplashAd *)splashAd {
    NSLog(@"%s,===%@", __func__, [splashAd getRequestId]);
}

/**
 开屏广告曝光回调

 @param splashAd 开屏对象
 */
- (void)HZZF_splashAdExposured:(HZZFAdSDKSplashAd *)splashAd {
    NSLog(@"%s,===%@", __func__, [splashAd getRequestId]);
}



/**
 开屏广告加载失败
 
 @param splashAd 开屏对象
 */
- (void)HZZF_splashAdDidFailToLoad:(HZZFAdSDKSplashAd *)splashAd error:(NSError *)error {
    NSLog(@"%s,===%@", __func__, [splashAd getRequestId]);
}

/**
 *  开屏广告成功展示
 *
 *  @param splashAd 开屏对象
 */
- (void)HZZF_splashAdSuccessPresentScreen:(HZZFAdSDKSplashAd *)splashAd {
    NSLog(@"%s,===%@", __func__, [splashAd getRequestId]);
}

/**
 *  开屏广告展示失败
 *
 *  @param splashAd 开屏对象
 */
- (void)HZZF_splashAdFailToPresent:(HZZFAdSDKSplashAd *)splashAd withError:(NSError *)error {
    NSLog(@"%s,===%@", __func__, [splashAd getRequestId]);
}

/**
 *  开屏广告关闭落地页
 *
 *  @param splashAd 开屏对象
 */
- (void)HZZF_splashAdCloseLandingPage:(HZZFAdSDKSplashAd *)splashAd {
    NSLog(@"%s,===%@", __func__, [splashAd getRequestId]);
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
